package com.ss.android.article.base.feature.video.cdn.data;

import android.net.Uri;
import android.text.TextUtils;
import com.ss.android.article.base.feature.video.MediaHelper;
import java.util.ArrayList;
import java.util.Iterator;
import org.json.JSONArray;
import org.json.JSONObject;

public class SSCdnCacheItem {
    private static final int CDN_TEST_LIVE_TIME = 86400000;
    public ArrayList hostItemArrayList;
    public String identifier;
    public boolean isSuccess;
    public boolean isTachometering;
    public long lastTachometerTime;

    public SSCdnCacheItem() {
        this.identifier = null;
        this.isSuccess = false;
        this.isTachometering = false;
        this.lastTachometerTime = 0;
        this.hostItemArrayList = null;
    }

    public boolean canSocreUrls() {
        boolean v0 = (this.isTachometering) || !this.isSuccess || (TextUtils.isEmpty(this.identifier)) ? false : true;
        return v0;
    }

    public void extractFields(JSONObject arg3) {
        this.hostItemArrayList = new ArrayList();
        SSCdnHostItem v0 = new SSCdnHostItem();
        v0.parseCdnUrl("http://v4.pstatp.com/origin/6146/6527705470.mp4");
        this.hostItemArrayList.add(v0);
        v0 = new SSCdnHostItem();
        v0.parseCdnUrl("http://v6.pstatp.com/origin/6146/6527705470?KSSAccessKeyId=qh0h9TdcEMrm1VlR2ad%2F&Expires=3600859576&Signature=d%2B%2BkL6%2BjUYE7wWTjYHvFanfRIZk%3D");
        this.hostItemArrayList.add(v0);
        v0 = new SSCdnHostItem();
        v0.parseCdnUrl("http://v7.pstatp.com/fb30bb2fe1e7360a93bcf66fa5518e76/696cbb36/origin/6146/6527705470.mp4");
        this.hostItemArrayList.add(v0);
    }

    private SSCdnHostItem findHostItem(String arg5) {
        Object v0_1;
        SSCdnHostItem v0;
        SSCdnHostItem v1 = null;
        if(TextUtils.isEmpty(((CharSequence)arg5))) {
          return null;
        } else {
            Iterator v2 = this.hostItemArrayList.iterator();
            do {
                if(v2.hasNext()) {
                    v0_1 = v2.next();
                    if(!((SSCdnHostItem)v0_1).cdnDomain.equals(arg5)) {
                        continue;
                    }

                    break;
                }
                else {
                   return v1;
                }
            }
            while(true);
            return (SSCdnHostItem) v0_1;
        }
    }

    public boolean isLossEfficacy() {
        boolean v0 = System.currentTimeMillis() - this.lastTachometerTime > 86400000 ? true : false;
        return v0;
    }

    public JSONObject log() {
        JSONObject v0;
        JSONObject v2 = null;
        if(this.hostItemArrayList == null) {
            v0 = v2;
            return v0;
        }

        try {
            JSONObject v3 = new JSONObject();
            JSONArray v4 = new JSONArray();
            JSONArray v5 = new JSONArray();
            Iterator v6 = this.hostItemArrayList.iterator();
            while(v6.hasNext()) {
                Object v0_2 = v6.next();
                JSONObject v1 = new JSONObject();
                v1.put(((SSCdnHostItem)v0_2).cdnDomain, ((SSCdnHostItem)v0_2).cdnGetIPCostTime);
                v5.put(v1);
                JSONArray v7 = new JSONArray();
                Iterator v8 = ((SSCdnHostItem)v0_2).cdnIPArrayList.iterator();
                while(v8.hasNext()) {
                    Object v1_1 = v8.next();
                    JSONObject v9 = new JSONObject();
                    v9.put(((SSCdnIpItem)v1_1).ipAddress, ((SSCdnIpItem)v1_1).ipCostTime);
                    v7.put(v9);
                }

                v1 = new JSONObject();
                v1.put(((SSCdnHostItem)v0_2).cdnDomain, v7);
                v4.put(v1);
            }

            v3.put("speed", v4);
            v3.put("dns", v5);
            return v3;
        }
        catch(Exception v0_1) {
            v0 = v2;
        }

        return v0;
    }

    public int scoreUrl(String arg3) {
        int v0 = 500;
        if(!TextUtils.isEmpty(((CharSequence)arg3))) {
            Uri v1 = Uri.parse(MediaHelper.getVideoSource(arg3));
            if(v1 != null) {
                SSCdnHostItem v1_1 = this.findHostItem(v1.getHost());
                if(v1_1 != null) {
                    v0 = v1_1.cdnRank;
                }
            }
        }

        return v0;
    }
}

